<?php
include_once("inc/connection.php");
include_once("inc/constants.inc.php");
session_start();

if(!isset($_SESSION['login']) || empty($_SESSION['login']) || !isset($_SESSION['email']) || empty($_SESSION['email']) || !isset($_SESSION['user_role']))
	{
		header("Location: login.php?error=invalid-access");
		exit(0);
	}
elseif($_SESSION['user_role']==2)
	{
		header("Location: test.php?error=invalid-access");
		exit(0);
	}

 
if(isset($_GET['add-type']))
	{
	?>
	     <fieldset><legend><h3>Add Question Type</h3></legend>
		 <form name="input" action="process/add-update-type.php" method="post">
			<?php
				echo "<table class='table table-bordered table-striped'>
				<thead>
				<tr>
					<th>Question Type </th>
				</tr></thead>";
				
					echo "<tbody><tr>";
					echo "<td><input type='text' name='QType'></td>";
					echo "</tr></tbody>";
				    echo "</table>";
				    echo "<br>";
			?>
			 <input class="btn btn-default menuspan" type="submit" name="add-type" value="Add Question Type" />
		</form>
		
		<?php
	       }
if(isset($_GET['update-type']) && isset($_GET['radiobutton']) )
	{
	?>
	<fieldset><legend><h3>Update Question Type</h3></legend>
		<form name="input" action="process/add-update-type.php" method="post">
			<?php
			echo "<table class='table table-bordered table-striped'>
			<thead>
			<tr>
				<th>Question Type ID</th>
				<th>Question Type </th>
			</tr></thead>";
			
		    $QuestiontypeId = $_GET['radiobutton'];
			echo "<td><input type='hidden' name='QTypeID' value='$QuestiontypeId'></td>";
			
		    $result = mysql_query("SELECT * FROM question_type WHERE QTypeID='$QuestiontypeId'");
			while($row = mysql_fetch_array($result))
			{
				echo "<tbody><tr>";
				echo "<td>" . $row['QTypeID'] . "</td>";
				echo "<td><input type='text' name='QType' value=". $row['QType']. "></td>";
				echo "</tr></tbody>";
			}
			echo "</table>";
			?>
			 <input class="btn btn-default menuspan" type="submit" name="update-type" value="Update" />
		</form>
		 <?php
	}
	
	if(isset($_GET['delete-type']) && isset($_GET['radiobutton']))
	{
	  $questiontypeid = $_GET['radiobutton'];
	  $url="process/add-update-type.php?del_id=$questiontypeid";             // to reload the server
        header("Refresh:0;URL=$url");
        exit(0);
	}

?>